package br.com.solutions.delivery.factory.dao;

import br.com.solutions.delivery.dao.SerializationDao;
import br.com.solutions.delivery.dao.intf.IDao;
import java.util.HashMap;
import java.util.Map;

public class FactoryDAO {
    
    private static FactoryDAO instance;
    
    private FactoryDAO(){
        super();
    }
    
    public static FactoryDAO getInstance(){
        if (instance == null){
            instance = new FactoryDAO();
        }
        
        return instance;
    }
    
    @SuppressWarnings("unchecked")
    private Map<String, IDao<?>> map = new HashMap<String, IDao<?>>();
	
    @SuppressWarnings("unchecked")
    public <M> IDao<M> getDao(Class<M> clazz){
        if (map.get(clazz.getName()) == null){
                IDao<M> newDao = new SerializationDao<M>(clazz.getSimpleName());
                map.put(clazz.getSimpleName(), newDao);
        }

        return (IDao<M>) map.get(clazz.getSimpleName());
    }
    
}
